home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_libungif.idb / usr / freeware / include / gif_lib.h.z / gif_lib.h
Encoding:
C/C++ Source or Header  |  1999-04-16  |  11.8 KB  |  302 lines

  1. /******************************************************************************
  2. * In order to make life a little bit easier when using the GIF file format,   *
  3. * this library was written, and which does all the dirty work...              *
  4. *                                                                             *
  5. *                                        Written by Gershon Elber,  Jun. 1989 *
  6. *                                        Hacks by Eric S. Raymond,  Sep. 1992 *
  7. *******************************************************************************
  8. * History:                                                                    *
  9. * 14 Jun 89 - Version 1.0 by Gershon Elber.                                   *
  10. *  3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)  *
  11. * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)   *
  12. * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)             * 
  13. * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)     *
  14. ******************************************************************************/
  15.  
  16. #ifndef GIF_LIB_H
  17. #define GIF_LIB_H
  18.  
  19. #define GIF_LIB_VERSION    " Version 4.0, "
  20.  
  21. #define    GIF_ERROR    0
  22. #define GIF_OK        1
  23.  
  24. #ifndef TRUE
  25. #define TRUE        1
  26. #define FALSE        0
  27. #endif
  28.  
  29. #ifndef NULL
  30. #define NULL        0
  31. #endif /* NULL */
  32.  
  33. #define GIF_FILE_BUFFER_SIZE 16384  /* Files uses bigger buffers than usual. */
  34.  
  35. typedef    int        GifBooleanType;
  36. typedef    unsigned char    GifPixelType;
  37. typedef unsigned char *    GifRowType;
  38. typedef unsigned char    GifByteType;
  39.  
  40. #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
  41. #define GIF_EXIT(Msg)    { GIF_MESSAGE(Msg); exit(-3); }
  42.  
  43. #ifdef SYSV
  44. #define VoidPtr char *
  45. #else
  46. #define VoidPtr void *
  47. #endif /* SYSV */
  48.  
  49. typedef struct GifColorType {
  50.     GifByteType Red, Green, Blue;
  51. } GifColorType;
  52.  
  53. typedef struct ColorMapObject
  54. {
  55.     int    ColorCount;
  56.     int BitsPerPixel;
  57.     GifColorType *Colors;        /* on malloc(3) heap */
  58. }
  59. ColorMapObject;
  60.  
  61. typedef struct GifImageDesc {
  62.     int Left, Top, Width, Height,    /* Current image dimensions. */
  63.     Interlace;            /* Sequential/Interlaced lines. */
  64.     ColorMapObject *ColorMap;        /* The local color map */
  65. } GifImageDesc;
  66.  
  67. typedef struct GifFileType {
  68.     int SWidth, SHeight,        /* Screen dimensions. */
  69.     SColorResolution,         /* How many colors can we generate? */
  70.     SBackGroundColor;        /* I hope you understand this one... */
  71.     ColorMapObject *SColorMap;        /* NULL if not exists. */
  72.     int ImageCount;            /* Number of current image */
  73.     GifImageDesc Image;            /* Block describing current image */
  74.     struct SavedImage *SavedImages;    /* Use this to accumulate file state */
  75.     VoidPtr UserData;           /* hook to attach user data (TVT) */
  76.     VoidPtr Private;              /* Don't mess with this! */
  77. } GifFileType;
  78.  
  79. typedef enum {
  80.     UNDEFINED_RECORD_TYPE,
  81.     SCREEN_DESC_RECORD_TYPE,
  82.     IMAGE_DESC_RECORD_TYPE,        /* Begin with ',' */
  83.     EXTENSION_RECORD_TYPE,        /* Begin with '!' */
  84.     TERMINATE_RECORD_TYPE        /* Begin with ';' */
  85. } GifRecordType;
  86.  
  87. /* DumpScreen2Gif routine constants identify type of window/screen to dump.  */
  88. /* Note all values below 1000 are reserved for the IBMPC different display   */
  89. /* devices (it has many!) and are compatible with the numbering TC2.0        */
  90. /* (Turbo C 2.0 compiler for IBM PC) gives to these devices.             */
  91. typedef enum {
  92.     GIF_DUMP_SGI_WINDOW = 1000,
  93.     GIF_DUMP_X_WINDOW = 1001
  94. } GifScreenDumpType;
  95.  
  96. /* func type to read gif data from arbitrary sources (TVT) */
  97. typedef int (*InputFunc)(GifFileType*,GifByteType*,int);
  98.  
  99. /* func type to write gif data ro arbitrary targets.
  100.  * Returns count of bytes written. (MRB)
  101.  */
  102. typedef int (*OutputFunc)(GifFileType *, const GifByteType *, int);
  103. /******************************************************************************
  104. *  GIF89 extension function codes                                             *
  105. ******************************************************************************/
  106.  
  107. #define COMMENT_EXT_FUNC_CODE        0xfe    /* comment */
  108. #define GRAPHICS_EXT_FUNC_CODE        0xf9    /* graphics control */
  109. #define PLAINTEXT_EXT_FUNC_CODE        0x01    /* plaintext */
  110. #define APPLICATION_EXT_FUNC_CODE    0xff    /* application block */
  111.  
  112. /******************************************************************************
  113. * O.K., here are the routines one can access in order to encode GIF file:     *
  114. * (GIF_LIB file EGIF_LIB.C).                              *
  115. ******************************************************************************/
  116.  
  117. GifFileType *EGifOpenFileName(char *GifFileName, int GifTestExistance);
  118. GifFileType *EGifOpenFileHandle(int GifFileHandle);
  119. GifFileType *EgifOpen(void *userPtr, OutputFunc writeFunc);
  120. int EGifSpew(GifFileType *GifFile);
  121. void EGifSetGifVersion(char *Version);
  122. int EGifPutScreenDesc(GifFileType *GifFile,
  123.     int GifWidth, int GifHeight, int GifColorRes, int GifBackGround,
  124.     ColorMapObject *GifColorMap);
  125. int EGifPutImageDesc(GifFileType *GifFile,
  126.     int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace,
  127.     ColorMapObject *GifColorMap);
  128. int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
  129. int EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel);
  130. int EGifPutComment(GifFileType *GifFile, char *GifComment);
  131. int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen,
  132.                             VoidPtr GifExtension);
  133. int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
  134.                            GifByteType *GifCodeBlock);
  135. int EGifPutCodeNext(GifFileType *GifFile, GifByteType *GifCodeBlock);
  136. int EGifCloseFile(GifFileType *GifFile);
  137.  
  138. #define    E_GIF_ERR_OPEN_FAILED    1        /* And EGif possible errors. */
  139. #define    E_GIF_ERR_WRITE_FAILED    2
  140. #define E_GIF_ERR_HAS_SCRN_DSCR    3
  141. #define E_GIF_ERR_HAS_IMAG_DSCR    4
  142. #define E_GIF_ERR_NO_COLOR_MAP    5
  143. #define E_GIF_ERR_DATA_TOO_BIG    6
  144. #define E_GIF_ERR_NOT_ENOUGH_MEM 7
  145. #define E_GIF_ERR_DISK_IS_FULL    8
  146. #define E_GIF_ERR_CLOSE_FAILED    9
  147. #define E_GIF_ERR_NOT_WRITEABLE    10
  148.  
  149. /******************************************************************************
  150. * O.K., here are the routines one can access in order to decode GIF file:     *
  151. * (GIF_LIB file DGIF_LIB.C).                              *
  152. ******************************************************************************/
  153.  
  154. GifFileType *DGifOpenFileName(const char *GifFileName);
  155. GifFileType *DGifOpenFileHandle(int GifFileHandle);
  156. GifFileType *DGifOpen( void* userPtr, InputFunc readFunc );  /* new one (TVT) */
  157. int DGifSlurp(GifFileType *GifFile);
  158. int DGifGetScreenDesc(GifFileType *GifFile);
  159. int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
  160. int DGifGetImageDesc(GifFileType *GifFile);
  161. int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
  162. int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
  163. int DGifGetComment(GifFileType *GifFile, char *GifComment);
  164. int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
  165.                         GifByteType **GifExtension);
  166. int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
  167. int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
  168.                         GifByteType **GifCodeBlock);
  169. int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
  170. int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
  171. int DGifCloseFile(GifFileType *GifFile);
  172.  
  173. #define    D_GIF_ERR_OPEN_FAILED    101        /* And DGif possible errors. */
  174. #define    D_GIF_ERR_READ_FAILED    102
  175. #define    D_GIF_ERR_NOT_GIF_FILE    103
  176. #define D_GIF_ERR_NO_SCRN_DSCR    104
  177. #define D_GIF_ERR_NO_IMAG_DSCR    105
  178. #define D_GIF_ERR_NO_COLOR_MAP    106
  179. #define D_GIF_ERR_WRONG_RECORD    107
  180. #define D_GIF_ERR_DATA_TOO_BIG    108
  181. #define D_GIF_ERR_NOT_ENOUGH_MEM 109
  182. #define D_GIF_ERR_CLOSE_FAILED    110
  183. #define D_GIF_ERR_NOT_READABLE    111
  184. #define D_GIF_ERR_IMAGE_DEFECT    112
  185. #define D_GIF_ERR_EOF_TOO_SOON    113
  186.  
  187. /******************************************************************************
  188. * O.K., here are the routines from GIF_LIB file QUANTIZE.C.              *
  189. ******************************************************************************/
  190. int QuantizeBuffer(unsigned int Width, unsigned int Height, int *ColorMapSize,
  191.     GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput,
  192.     GifByteType *OutputBuffer, GifColorType *OutputColorMap);
  193.  
  194.  
  195. /******************************************************************************
  196. * O.K., here are the routines from GIF_LIB file QPRINTF.C.              *
  197. ******************************************************************************/
  198. extern int GifQuietPrint;
  199.  
  200. #ifdef USE_VARARGS
  201. extern void GifQprintf();
  202. #else
  203. extern void GifQprintf(char *Format, ...);
  204. #endif /* USE_VARARGS */
  205.  
  206. /******************************************************************************
  207. * O.K., here are the routines from GIF_LIB file GIF_ERR.C.              *
  208. ******************************************************************************/
  209. extern void PrintGifError(void);
  210. extern int GifLastError(void);
  211.  
  212. /******************************************************************************
  213. * O.K., here are the routines from GIF_LIB file DEV2GIF.C.              *
  214. ******************************************************************************/
  215. extern int DumpScreen2Gif(char *FileName,
  216.               int ReqGraphDriver,
  217.               int ReqGraphMode1,
  218.               int ReqGraphMode2,
  219.               int ReqGraphMode3);
  220.  
  221. /*****************************************************************************
  222.  *
  223.  * Everything below this point is new after version 1.2, supporting `slurp
  224.  * mode' for doing I/O in two big belts with all the image-bashing in core.
  225.  *
  226.  *****************************************************************************/
  227.  
  228. /******************************************************************************
  229. * Color Map handling from ALLOCGIF.C                          *
  230. ******************************************************************************/
  231.  
  232. extern ColorMapObject *MakeMapObject(int ColorCount, GifColorType *ColorMap);
  233. extern void FreeMapObject(ColorMapObject *Object);
  234. extern ColorMapObject *UnionColorMap(ColorMapObject *ColorIn1,
  235.                   ColorMapObject *ColorIn2,
  236.                   GifPixelType ColorTransIn2[]);
  237. extern int BitSize(int n);
  238.  
  239. /******************************************************************************
  240. * Support for the in-core structures allocation (slurp mode).              *
  241. ******************************************************************************/
  242.  
  243. /* This is the in-core version of an extension record */
  244. typedef struct {
  245.     int        ByteCount;
  246.     char    *Bytes;        /* on malloc(3) heap */
  247.     int Function;       /* Holds the type of the Extension block. */
  248. } ExtensionBlock;
  249.  
  250. /* This holds an image header, its unpacked raster bits, and extensions */
  251. typedef struct SavedImage {
  252.     GifImageDesc    ImageDesc;
  253.  
  254.     char        *RasterBits;        /* on malloc(3) heap */
  255.  
  256.     int            Function; /* DEPRECATED: Use ExtensionBlocks[x].Function
  257.                            * instead */
  258.     int            ExtensionBlockCount;
  259.     ExtensionBlock    *ExtensionBlocks;    /* on malloc(3) heap */
  260. } SavedImage;
  261.  
  262. extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
  263.  
  264. extern void MakeExtension(SavedImage *New, int Function);
  265. extern int AddExtensionBlock(SavedImage *New, int Len, char ExtData[]);
  266. extern void FreeExtension(SavedImage *Image);
  267.  
  268. extern SavedImage *MakeSavedImage(GifFileType *GifFile, SavedImage *CopyFrom);
  269. extern void FreeSavedImages(GifFileType *GifFile);
  270.  
  271. /******************************************************************************
  272. * The library's internal utility font                          *
  273. ******************************************************************************/
  274.  
  275. #define GIF_FONT_WIDTH    8
  276. #define GIF_FONT_HEIGHT    8
  277. extern unsigned char AsciiTable[][GIF_FONT_WIDTH];
  278.  
  279. extern void DrawText(SavedImage *Image,
  280.              const int x, const int y,
  281.              const char *legend,
  282.              const int color);
  283.  
  284. extern void DrawBox(SavedImage *Image,
  285.              const int x, const int y,
  286.              const int w, const int d,
  287.              const int color);
  288.  
  289. void DrawRectangle(SavedImage *Image,
  290.              const int x, const int y,
  291.              const int w, const int d,
  292.              const int color);
  293.  
  294. extern void DrawBoxedText(SavedImage *Image,
  295.              const int x, const int y,
  296.              const char *legend,
  297.              const int border,
  298.              const int bg,
  299.              const int fg);
  300.  
  301. #endif /* GIF_LIB_H */
  302.